// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

#include "simple_handler.h"

#include <windows.h>
#include <string>

#include "include/cef_browser.h"

void SimpleHandler::CenterWindow(CefWindowHandle hwnd, int width, int height) {
    int screen_w = GetSystemMetrics(SM_CXSCREEN);
    int screen_h = GetSystemMetrics(SM_CYSCREEN);
    
    SetWindowPos(hwnd, HWND_TOP, (screen_w - width)/2, 
        (screen_h - height)/2, width, height, SWP_NOREDRAW);
}

void SimpleHandler::PlatformTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title) {
  CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle();
  if (hwnd){
    if(title!="uavs")
      SetWindowText(hwnd, std::wstring(title).c_str());
    
    static bool login = false;
    if(title=="登录" || title=="uavs" || title=="login") {
      CenterWindow(hwnd,600,350);
      login = true;
    }else{
      if(login) CenterWindow(hwnd,1400,800);
      login = false;
    }
  }
}
